﻿
//Copyright 1997-2009 Syrinx Development, Inc.
//This file is part of the Syrinx Web Application Framework (SWAF).
// == BEGIN LICENSE ==
//
// Licensed under the terms of any of the following licenses at your
// choice:
//
//  - GNU General Public License Version 3 or later (the "GPL")
//    http://www.gnu.org/licenses/gpl.html
//
//  - GNU Lesser General Public License Version 3 or later (the "LGPL")
//    http://www.gnu.org/licenses/lgpl.html
//
//  - Mozilla Public License Version 1.1 or later (the "MPL")
//    http://www.mozilla.org/MPL/MPL-1.1.html
//
// == END LICENSE ==
using System;
using System.Collections.Generic;
using System.Text;

using Swaf;
using Swaf.BizObj;
using Swaf.Gui;
using Swaf.Security;

namespace PageEditing.Gui
{
	public class SalEditingManagementBizProc : BaseBusinessProcess
	{
		public SalEditingManagementBizProc(ActiveBizProc procState) : base(procState) { }
		
		protected override void setupRuleNames()
		{
			m_getBizObjListRule = "getPageStandAloneArticleLists";
			m_updateBizObjRule = "updateStandAloneArticleList";
		}

		protected override Privileges CurrentEditPrivilege
		{
			get { return CurrentPrincipal.getPrivilege("AppFunctions.ManageCompanyConfiguration"); }
		}

		protected override object[] getBizObjListRuleParameters(object parentId, IBizObj filterSort)
		{
			return new object[] {parentId, false };
		}

		protected override IBizObjList getListFromBizRuleResults(IResults rc)
		{
			IBizObjList sals = null;
			IBizObj pageInfo = rc.CallResults as IBizObj;
			if (pageInfo != null)
				sals = pageInfo.get("sals") as IBizObjList;
			if (sals != null && sals.numElements == 0)
				sals.insertNew();
			return sals;
		}

		protected override object[] getUpdateBizRuleParameters(IBizObj bizObj)
		{
			object parentBizObjId = m_procState.get("pid");
			return new object[] { parentBizObjId, bizObj };
		}

		public void previewCurrentSal()
		{
			base.updateBizObj(true);
			IResults rc = App.ruleMgr.execute("getSalHtml", CurrentBizObj);
			m_currentBizObj.put("salHtml", rc.CallResults as string);
			m_retrievedCurrentBizObj = true;
			//IWidget previewWidget = m_procState.BPC.HostView.findWidget(m_procState.get("previewWidgetId") as string);
			//if (previewWidget != null)
			//	Cmn.callMethod(previewWidget, "setupOptionsFromBizObj", new Type[] { typeof(IBizObj) }, new object[] { CurrentBizObj });



			//IResults rc = App.ruleMgr.execute("createSalPreviewPage", CurrentBizObj);
			//string salPreviewUrl = rc.CallResults as string;
			//CurrentBizObj.put("salPreviewUrl", salPreviewUrl);
		}

		protected override void setupActions()
		{
			base.setupActions();
			Actions.addAction(new GenericAction("Preview", true, previewCurrentSal, this));
		}
	}
}
